package com.dwin.h5.app.h5;

import android.util.Log;

import java.util.LinkedList;
import java.util.Queue;

/**
 * js 发送，收发消息中转桥。
 * 避免阻塞主线程
 */
public class H5MessageTool {
    private static final String TAG = "H5MessageTool";

    // 接收到的消息的队列
    private Queue<String> receiveMsg = new LinkedList<String>();
    // 待发送的消息的队列
    private Queue<String> sendMsg = new LinkedList<String>();

    public H5MessageTool() {
    }

    public void addSendMsg(String msg) {
        Log.d(TAG, "OnSendMessage: " + msg);
        sendMsg.offer(msg);
    }

    public String getSendMsg() {
        //返回第一个元素，并在队列中删除
        return sendMsg.poll();
    }

    public void addReceiveMsg(String msg) {
        Log.d(TAG, "OnReceiveMessage: " + msg);
        receiveMsg.offer(msg);
    }

    public String getReceiveMsg() {
        //返回第一个元素，并在队列中删除
        return receiveMsg.poll();
    }

    public int getReceiveMsgCount() {
        return receiveMsg.size();
    }

    public int getSendMsgCount() {
        return sendMsg.size();
    }

}
